<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_job2dao/model')->方法名();
*/
namespace jy_job2dao;
defined('BY_JYA') or exit('error');
class merch extends \plugin{
	public function onemerch($postdata=array()){
		$pid=pdo_getcolumn('jy_51job_merch_group',array('title'=>trim($postdata['companycate']),'uniacid'=>$_SESSION['uniacid']),'id');
		if($pid){
			$cids=';'.$pid.';';
		}else{
			$newgroup=array(
				'uniacid'=>$_SESSION['uniacid'],
				'title'=>trim($postdata['companycate']),
				'status'=>1,
				'createtime'=>time()
			);
			pdo_insert('jy_51job_merch_group',$newgroup);
			$pid=pdo_insertid();
			$cids=';'.$pid.';';
		}
		$merchid=pdo_getcolumn('jy_51job_merch',array('oid'=>trim($postdata['id']),'uniacid'=>$_SESSION['uniacid']),'id');
		if($merchid){
			return '';
		}
		$type=0;
		if($postdata['companytype']=='国有制'){
			$type=1;
		}elseif($postdata['companytype']=='上市公司'){
			$type=2;
		}elseif($postdata['companytype']=='合资公司'){
			$type=3;
		}elseif($postdata['companytype']=='外企'){
			$type=4;
		}elseif($postdata['companytype']=='非营利性企业'){
			$type=5;
		}elseif($postdata['companytype']=='个体工商户'){
			$type=6;
		}
		$teamtype=0;
		$companyworker=$postdata['companyworker'];
		if(substr($postdata['companyworker'],-1)=='+'){
			$companyworker=substr($postdata['companyworker'],0,-1);
		}
		$companyworker=intval($companyworker);
		if($companyworker<=10){
			$teamtype=0;
		}elseif($companyworker>100){
			$teamtype=4;
		}elseif($companyworker>50){
			$teamtype=3;
		}elseif($companyworker>30){
			$teamtype=2;
		}elseif($companyworker>10){
			$teamtype=1;
		}
		$pcd=array('city'=>$postdata['city'],'district'=>$postdata['district']);
		$lat_lng=array('lat'=>$postdata['lat'],'lng'=>$postdata['lng']);
		$data=array(
				'oid'=>trim($postdata['id']),
				'title'=>trim($postdata['companyname']),
				'pid'=>$pid,
				'cids'=>$cids,
				'type'=>$type,
				'teamtype'=>$teamtype,
				'teamnum'=>$postdata['companyworker'],
				'name'=>trim($postdata['mastername']),
				'mobile'=>trim($postdata['tel']),
				'address'=>trim($postdata['address']),
				'email'=>trim($postdata['email']),
				'weixin'=>trim($postdata['weixin']),
				'content'=>trim($postdata['content']),
				'codeimg'=>trim($postdata['cardimg']),
				'logo'=>trim($postdata['thumb']),
				'status'=>intval($postdata['status'])?0:1,
				'createtime'=>intval($postdata['createtime']),
				'updatetime'=>intval($postdata['updatetime']),
				'endtime'=>intval($postdata['endtime']),
				'city'=>$postdata['city'],
				'district'=>$postdata['district'],
				'pcd'=>ijson_encode($pcd),
				'lat_lng'=>ijson_encode($lat_lng),
				'looks'=>intval($postdata['looks']),
				'paixu'=>intval($postdata['sort']),
				'isrecommand'=>intval($postdata['isrecommand']),
				'notenum'=>trim($postdata['notenum']),
				'daynum'=>trim($postdata['daynum']),
				'lastviewtime'=>trim($postdata['lastviewtime']),
				'jobnum'=>trim($postdata['jobnum']),
				'jobnum_day'=>trim($postdata['jobnum_day']),
				'lastviewtime_job'=>trim($postdata['lastviewtime_job']),
				'top_day'=>trim($postdata['top_day']),
				'lastviewtime_top'=>trim($postdata['lastviewtime_top']),
				'taocanid'=>$postdata['roleid'],
		);
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_51job_merch',$data);
		$merchid=pdo_insertid();
		return '';
	}
	public function merch_account($postdata=array()){
		$isadd=pdo_getcolumn('jy_51job_merch_account',array('oid'=>trim($postdata['id']),'uniacid'=>$_SESSION['uniacid']),'id');
		if($isadd){
			return '';
		}
		$mid=pdo_getcolumn('jy_job2dao_member',array('fmid'=>trim($postdata['uid']),'uniacid'=>$_SESSION['uniacid']),'mid');
		$merchid=pdo_getcolumn('jy_51job_merch',array('oid'=>trim($postdata['companyid']),'uniacid'=>$_SESSION['uniacid']),'id');
		$data=array(
			'oid'=>trim($postdata['id']),
			'name'=>trim($postdata['name']),
			'mid'=>$mid,
			'password'=>trim($postdata['password']),
			'password2'=>trim($postdata['password2']),
			'createtime'=>trim($postdata['createtime']),
			'status'=>trim($postdata['status'])?0:1,
			'logintime'=>trim($postdata['logintime']),
			'merchid'=>$merchid,
			'varifycode'=>trim($postdata['varifycode']),
			'varifytime'=>trim($postdata['varifytime']),
		);
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_51job_merch_account',$data);
		return '';
	}
	//搬移职位数据
	public function merch_job($postdata=array()){
		$merchid=pdo_getcolumn('jy_51job_merch',array('oid'=>trim($postdata['companyid']),'uniacid'=>$_SESSION['uniacid']),'id');
		$isadd=pdo_getcolumn('jy_51job_job',array('oid'=>$postdata['id'],'uniacid'=>$_SESSION['uniacid']),'id');
		if($isadd){
			return '';
		}
		$pid=pdo_getcolumn('jy_51job_job_group',array('title'=>trim($postdata['jobgrouptitle']),'uniacid'=>$_SESSION['uniacid']),'id');
		if(!$pid && $postdata['jobgrouptitle']){
			$newgroup=array(
				'uniacid'=>$_SESSION['uniacid'],
				'title'=>trim($postdata['jobgrouptitle']),
				'status'=>1,
				'createtime'=>time()
			);
			pdo_insert('jy_51job_job_group',$newgroup);
			$pid=pdo_insertid();
		}
		if($postdata['jobtype']=='全职'){
			$jobtype=0;
		}elseif($postdata['jobtype']=='兼职'){
			$jobtype=1;
		}elseif($postdata['jobtype']=='实习'){
			$jobtype=2;
		}
		$special=trim($postdata['special']);
		$special=str_array($special,',');
		$special2=';';
		foreach($special as $sv){
			$special2.=$sv.';';
		}
		$data=array(
			'oid'=>trim($postdata['id']),
			'title'=>trim($postdata['jobtitle']),
			'price'=>trim($postdata['money']),
			'merchid'=>$merchid,
			'zhaonum'=>trim($postdata['num']),
			'ageinfo'=>trim($postdata['age']),
			'education'=>trim($postdata['education']),
			'xueli'=>$this->xueli_type4[$postdata['education']],
			'express'=>trim($postdata['express']),
			'type'=>$jobtype,
			'sex'=>trim($postdata['sex']),
			'content'=>trim($postdata['content']),
			'paixu'=>trim($postdata['sort']),
			'status'=>trim($postdata['status'])?0:1,
			'endtime'=>trim($postdata['endtime']),
			'toptime'=>trim($postdata['toptime']),
			'updatetime'=>trim($postdata['updatetime']),
			'ishot'=>trim($postdata['isrecommand']),
			'pid'=>$pid,
			'createtime'=>trim($postdata['createtime']),
			'special'=>$special2,
		);
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_51job_job',$data);
		return '';
	}
}
?>